package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入书名-->");
        String name = scanner.nextLine();
        Book book = null;
        int i = 0;
        for (i = 0; i < bookList.getBookNum(); i++) {
            book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                break;
            }
        }
        if(i == bookList.getBookNum()) {
            System.out.println("查无此书");
        }else {
            if(bookList.getBook(i).isBorrow() == true) {
                bookList.getBook(i).setBorrow(false);
                System.out.println("归还成功");
            } else {
                System.out.println("此书已经归还");
            }

        }
    }
}
